package com.github.shiqiyue.app.api.sapi.controller.dbms.dto;

import com.github.shiqiyue.app.modules.dbms.entity.Database;
import lombok.Data;

import java.util.Date;

/***
 * 数据库 详情 DTO
 * @author wenyao.wu
 * @date:2019/8/6
 */
@Data
public class DatabaseDetailDTO {

    private Long id;

    private String name;

    private String url;

    private String username;

    private String remark;

    private Integer dbType;

    private Date addDate;

    private Date editDate;

    private String editUsername;

    private String addUsername;

    public static DatabaseDetailDTO newInstance(Database database) {
        DatabaseDetailDTO item = new DatabaseDetailDTO();
        item.setId(database.getId());
        item.setName(database.getName());
        item.setRemark(database.getRemark());
        item.setAddDate(database.getAddDate());
        item.setEditDate(database.getEditDate());
        item.setDbType(database.getDbType().getValue());
        item.setUsername(database.getUsername());
        item.setUrl(database.getUrl());
        if (database.getAddUser() != null) {
            item.setAddUsername(database.getAddUser().getName());
        }
        if (database.getEditUser() != null) {
            item.setEditUsername(database.getEditUser().getName());
        }
        return item;
    }

}
